<template>
  <div>
    <div style="display: flex;align-items: center;justify-content: center;">
      <el-card style="width: 80%;margin-top: 30px">
        <div style="margin-bottom: 10px;margin-left:5px;font-size: 20px;font-weight: bold;">首页推荐酒店</div>
        <div style="margin-bottom: 10px">
        </div>
        <el-table ref="userTable" :data="recommendData" stripe
                  :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}">
          <el-table-column prop="hotel_id" label="酒店id" align="center"></el-table-column>
          <el-table-column prop="url" label="图片">
            <template v-slot="scope">
              <div style="display: flex;align-items: center" align="center">
                <el-image style="width: 50px;height: 50px;border-radius: 50%" v-if="scope.row.hotel_id"
                          :src="`http://localhost:8000/hotel_image_download/${scope.row.hotel_id}`"
                          :preview-src-list="[scope.row.hotel_id]"></el-image>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="hotelname" label="酒店名"></el-table-column>
          <el-table-column prop="level" label="酒店级别"></el-table-column>
          <el-table-column prop="location" label="酒店地址"></el-table-column>
          <el-table-column prop="min_price" label="酒店最低价"></el-table-column>
          <el-table-column label="操作" width="150%" align="center">
            <template v-slot="scope">
              <el-button size="mini" type="danger" plain @click="cancel(scope.row.hotel_id)">取消推荐</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
  </div>
</template>
<script>
export default {
  name: "recommend",
  data() {
    return {
      recommendData: [],
    }
  },
  methods: {
    cancel(hotel_id) {
      this.$request.get('/hotel_recommend_delete/' + hotel_id + "/").then(res => {
        if (res.code === '200') {
          this.$message.success("取消成功")
          window.location.reload()
        } else if (res.code === '501') {
          this.$message.error(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    loadRecommend() {
      this.$request.get('/hotel_recommend_list/').then(res => {
        if (res.code === '200') {
          this.recommendData = res.data
          console.log(this.recommendData)
        } else if (res.code === '501') {
          this.$message.error(res.msg)
        } else {
          this.$message.error(res.msg)
        }
      })
    },
  },
  created() {
    this.loadRecommend()
  }
}
</script>
<style scoped>

</style>